﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace CSConsoleTest
{
    class TestAttribute : BaseConsoleTest
    {
        public void printDescription()
        {
            Console.WriteLine("--- Attributes ---");
        }

        public void doTest()
        {
            AttrTestObsolete obsolutedClassObj = new AttrTestObsolete();

            Type attrTestClassType = typeof(AttrTestCustom);
            Attribute[] attrs = Attribute.GetCustomAttributes(attrTestClassType);

            Console.WriteLine("AttrTestCustom class description");
            foreach (Attribute attr in attrs)
            {
                ClassDesc attrTest = attr as ClassDesc;
                Console.WriteLine("{0}\t{1}\t{2}", attrTest.Author, attrTest.Date, attrTest.Msg);
            }
        }
    }

    [Obsolete("This class is obsoleted")]
    class AttrTestObsolete
    {

    }

    [ClassDesc("myungpyo", Date="2013-05-07", Msg="Test class created")]
    [ClassDesc("myungpyo", Date = "2013-05-09", Msg = "Test class modified")]
    class AttrTestCustom
    {
    }

    [System.AttributeUsage(System.AttributeTargets.Class | System.AttributeTargets.Method, AllowMultiple=true)]
    class ClassDesc : System.Attribute
    {
        private string mAuthor;

        public string Author
        {
            set
            {
                mAuthor = value;
            }
            get
            {
                return mAuthor;
            }
        }
        public string Date { set; get; }
        public string Msg { set; get; }

        public ClassDesc(string aAuthor)
        {
            this.mAuthor = aAuthor;
        }
    }
}
